<?php

/**
 * URI Athority Wrapper
 * 
 * @author mgirouard
 */
class JSCasts_URI_Authority
extends JSCasts_URI_Component_Abstract
{
	private $userName;
	private $passWord;
	private $host;
	private $port;
	
	/**
	 * Syntax: [username[:password]@]host[:port]
	 * 
	 * @return unknown_type
	 */
	public function __toString()
	{
		$out = '';
		
		// Authentication information is optional
		if (!empty($this->userName)) {
			$out .= $this->username;
			
			// Passwords are optional too
			if (!empty($this->passWord)) {
				$out .= ':' . $this->passWord;
			}
			
			$out .= '@';
		}
		
		// Hostnames are required
		$out .= $this->host;
		
		// Port numbers are optional
		if (!empty($this->port)) {
			$out .= ':' . $this->port;
		}
		
		return $out;
	}
	
	public function userName($newValue = false)
	{
		return $this->setAndReturn('userName', $newValue);
	}
	
	public function passWord($newValue = false)
	{
		return $this->setAndReturn('passWord', $newValue);
	}
	
	public function host($newValue = false)
	{
		return $this->setAndReturn('host', $newValue);
	}
	
	public function port($newValue = false)
	{
		return $this->setAndReturn('port', $newValue);
	}
}